package com.lab.idea.bl.entity;

import cn.hutool.system.SystemUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.lab.idea.bl.pool.LabThreadPool;
import com.lab.idea.mybatis.entity.LabEntity;
import java.io.Serializable;
import java.util.List;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

/**
 * <p>
 * excel模板
 * </p>
 *
 * @author lab
 * @since 2023-11-06
 */
@Getter
@Setter
@Accessors(chain = true)
@TableName("bl_excel_template")
@ApiModel(value = "ExcelTemplate对象", description = "excel模板")
public class ExcelTemplate extends LabEntity<ExcelTemplate> {

    private static final long serialVersionUID = 1L;

    @TableId(value = "excelId", type = IdType.ASSIGN_ID)
    private String excelId;

    @TableField("excelName")
    private String excelName;

    @TableField("excelPath")
    private String excelPath;

    @TableField("docxPath")
    private String docxPath;

    @TableField("excelComment")
    private String excelComment;

    @TableField("corePoolSize")
    @ApiModelProperty("核心线程数")
    private Integer corePoolSize;

    @ApiModelProperty("最大线程数")
    @TableField("maxPoolSize")
    private Integer maxPoolSize;

    @ApiModelProperty("存活时间秒")
    @TableField("keepAliveTime")
    private Integer keepAliveTime;

    @ApiModelProperty("队列数量")
    @TableField("queueSize")
    private Integer queueSize;

    @TableField(value = "copyId",exist = false)
    private String copyId;

    @TableField(value = "sheets",exist = false)
    private List<ExcelSheet> sheets;

    public LabThreadPool threadPool() {
        LabThreadPool pool = new LabThreadPool();
        pool.setPoolName(this.excelName).setCorePoolSize(this.corePoolSize).setMaxPoolSize(this.maxPoolSize).setQueueSize(this.queueSize);
        if (pool.getCorePoolSize() == null || pool.getCorePoolSize() < 1) {
            pool.setCorePoolSize(4);
        }
        if (pool.getMaxPoolSize() == null || pool.getMaxPoolSize() < 1) {
            pool.setMaxPoolSize(20);
        }
        if (pool.getKeepAliveTime() == null || pool.getKeepAliveTime() < 1) {
            pool.setKeepAliveTime(60);
        }
        if (pool.getQueueSize() == null || pool.getQueueSize() < 1) {
            pool.setQueueSize(60);
        }
        return pool;
    }

    @Override
    public Serializable pkVal() {
        return this.excelId;
    }
}
